﻿using System;

using MugenMvvmToolkit.Interfaces;
using Windows.UI.Xaml.Navigation;

namespace MugenMvvmToolkitTest.TestInfrastructure
{
    public class TestNavigationService : INavigationService
    {
        #region Implementation of INavigationService

        /// <summary>
        ///     The <see cref="System.Uri" /> source.
        /// </summary>
        public Uri Source { get; set; }

        /// <summary>
        ///     Gets or sets the root page <see cref="IViewPageMappingItem" />
        /// </summary>
        public IViewPageMappingItem RootItem { get; set; }

        /// <summary>
        ///     The <see cref="Type" /> source.
        /// </summary>
        public Type SourcePageType { get; set; }

        /// <summary>
        ///     Indicates whether the navigator can navigate back.
        /// </summary>
        public bool CanGoBack { get; private set; }

        /// <summary>
        ///     Indicates whether the navigator can navigate forward.
        /// </summary>
        public bool CanGoForward { get; private set; }

        /// <summary>
        ///     The current <see cref="Type" /> source.
        /// </summary>
        public Type CurrentSourcePageType { get; private set; }

        /// <summary>
        ///     The current content.
        /// </summary>
        public object CurrentContent { get; private set; }

        /// <summary>
        ///     Navigates back.
        /// </summary>
        public void GoBack()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        ///     Navigates forward.
        /// </summary>
        public void GoForward()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        ///     Displays the content located at the specified <see cref="IViewPageMappingItem" />.
        /// </summary>
        /// <returns>
        ///     <c>true</c> if the content was successfully displayed; otherwise, <c>false</c>.
        /// </returns>
        /// <param name="source">
        ///     The <c>IViewPageMappingItem</c> of the content to display.
        /// </param>
        /// <param name="parameter">The specified parameter.</param>
        public bool Navigate(IViewPageMappingItem source, object parameter = null)
        {
            NavigatedPageMapping = source;
            return true;
        }

        /// <summary>
        ///     Navigates to the root page.
        /// </summary>
        public bool NavigateToRoot()
        {
            throw new NotImplementedException();
        }

        public event NavigatedEventHandler Navigated;

        public event NavigatingCancelEventHandler Navigating;

        public event NavigationFailedEventHandler NavigationFailed;

        public event NavigationStoppedEventHandler NavigationStopped;

        /// <summary>
        ///     Stops the loading process.
        /// </summary>
        public void StopLoading()
        {
            throw new NotImplementedException();
        }

        #endregion

        public void OnNavigating(NavigatingCancelEventArgs e)
        {
            NavigatingCancelEventHandler handler = Navigating;
            if (handler != null) handler(this, e);
        }

        public virtual void OnNavigated(NavigationEventArgs e)
        {
            NavigatedEventHandler handler = Navigated;
            if (handler != null) handler(this, e);
        }

        #region Properties

        public IViewPageMappingItem NavigatedPageMapping { get; set; }

        #endregion
    }
}